﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLL
{
    public class GiayChungNhanBLL
    {
        LandEntities data = new LandEntities();
        public GiayChungNhanBLL()
        { }

        public void ThemGiaySuDung(string maGSD, DateTime ngayKy,string nguoiKy,
            string chucVuNguoiKy, string donViCap, string maNguonGoc,string maCSD,string maThuaDat)
        {
            GCN_SDD giaySD = new GCN_SDD();
            giaySD.MAGCN = maGSD;
            giaySD.NGAYKY = ngayKy;
            giaySD.NGUOIKY = nguoiKy;
            giaySD.CHUCVUNGUOIKY = chucVuNguoiKy;
            giaySD.DONVICAP = donViCap;
            giaySD.MANGUONGOC = maNguonGoc;

            giaySD.THUADATs.Add(new THUADAT() { MATHUADAT = maThuaDat });
            giaySD.CHUSUDUNGs.Add(new CHUSUDUNG() { MACSD = maCSD });

            data.GCN_SDD.AddObject(giaySD);
            foreach (var thuadat in giaySD.THUADATs)
            {
                data.ObjectStateManager.ChangeObjectState(thuadat, System.Data.EntityState.Unchanged);
            }

            foreach (var chusudung in giaySD.CHUSUDUNGs)
            {
                data.ObjectStateManager.ChangeObjectState(chusudung, System.Data.EntityState.Unchanged);
            }
            data.SaveChanges();
        }

        public List<NGUONGOC> DanhSachNguonGoc()
        {
            var nguongoc = from ng in data.NGUONGOCs
                           select ng;
            return nguongoc.ToList<NGUONGOC>();
        }

        //public void ThemGiaySuDung_ChuSuDung(string maGSD, string MaCSD)
        //{
        //    GIAYCHUNGNHAN_CHUSUDUNG  gsdcsd = new GIAYCHUNGNHAN_CHUSUDUNG();
        //    gsdcsd.MACSD = maGSD;
        //    gsdcsd.MACSD = maGSD;
        //    data.GIAYCHUNGNHAN_CHUSUDUNG.AddObject(gsdcsd);
        //    data.SaveChanges();
        //}

        
    }
}
